import {userProfilesApi} from "../../request/api"
export default {
  namespaced:true,
  state: {
    cartTotal:0,//购物车数量
    userInfo:{
      nickName:"--",//昵称
      coin:"0",//积分
      headImg:require("../../assets/img/service.848ec511.png")//头像
    }
  },
  getters: {
  },
  mutations: {
    updateUserInfo(state,payload){
      state.cartTotal = payload.cartTotal;
      state.userInfo = payload.userInfo;
    },
    // 初始化用户信息
    initUserInfo(state,payload){
      state.cartTotal = 0,
      state.userInfo = {
        cartTotal:0,//购物车数量
        userInfo:{
          nickName:"--",//昵称
          coin:"0",//积分
          headImg:require("../../assets/img/service.848ec511.png")//头像
        }
      }
    }
  },
  actions: {
    async asyncChangeUserInfo({commit}){
      let res = await userProfilesApi()
      commit("updateUserInfo",res.data)
    }
  },
}